package com.pega.tulokhorecord.activity;

import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardArrayAdapter;
import it.gmariotti.cardslib.library.view.CardListView;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;

import com.pega.tulokhorecord.R;
import com.pega.tulokhorecord.data.ColorCard;

public class MainActivity extends Activity {

	private CardArrayAdapter mCardArrayAdapter;
	private ArrayList<Card> cards;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);

		ImageView iv_add = (ImageView) findViewById(R.id.iv_main_add);
		iv_add.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Toast.makeText(MainActivity.this, "Add", Toast.LENGTH_SHORT)
						.show();
			}
		});

		initCards();
	}

	private void initCards() {

		// Init an array of Cards
		cards = new ArrayList<Card>();
		for (int i = 0; i < 20; i++) {
			ColorCard card = new ColorCard(this);
			card.setTitle("A simple colored card " + i);
			card.setDate("12/12/2014");
			card.setCount(i);
			int a = i % 8;
			switch (a) {
			case 0:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color1);
				break;
			case 1:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color2);
				break;
			case 2:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color3);
				break;
			case 3:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color4);
				break;
			case 4:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color5);
				break;
			case 5:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color4);
				break;
			case 6:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color3);
				break;
			case 7:
				card.setBackgroundResourceId(R.drawable.demo_card_selector_color2);
				break;
			}

			cards.add(card);
		}

		mCardArrayAdapter = new CardArrayAdapter(this, cards);
		mCardArrayAdapter.setEnableUndo(true);
		CardListView listView = (CardListView) findViewById(R.id.carddemo_list_colors);
		if (listView != null) {
			/*
			 * SwingBottomInAnimationAdapter adapter = new
			 * SwingBottomInAnimationAdapter( mCardArrayAdapter);
			 * adapter.setAbsListView(listView);
			 * listView.setExternalAdapter(adapter, mCardArrayAdapter);
			 */
			listView.setAdapter(mCardArrayAdapter);
		}
	}

}